#include <cstdio>
#include <list>
#include<iostream>
using namespace std;

int LastRemaining_Solution1(unsigned int n, unsigned int m)
{
    if (n < 1 || m < 1)
        return -1;

    unsigned int i = 0;

    list<int> numbers;
    for (i = 0; i < n; ++i)
        numbers.push_back(i);

    list<int>::iterator current = numbers.begin();
    while (numbers.size() > 1)
    {
        for (int i = 1; i < m; ++i)
        {
            current++;
            if (current == numbers.end())
                current = numbers.begin();
        }

        list<int>::iterator next = ++current;
        if (next == numbers.end())
            next = numbers.begin();

        --current;
        cout << *(current)+1 << " ";
        numbers.erase(current);
        current = next;
    }
    cout << *(current)+1 <<endl;
    return *(current);
}

int main()
{
    int n[100], m[100];
    int i = 0,count;
    while(cin >> n[i] >> m[i])
    {
        if (n[i] != 0)
        {
            i++;

            continue;
        }
        else
            break;
    }
    for (count = 0; count < i; ++count)
    {
        LastRemaining_Solution1(n[count], m[count]);
    }
    return 0;
}